home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
archiver
/
compress.zoo
/
compress.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-06-30
|
26KB
|
621 lines
/*@H************************ < COMPRESS utility> ****************************
* *
* compress : compress.c *
* Main and Operating System Independent support functions *
* *
* port by : Donald J. Gloistein *
* *
* Source, Documentation, Object Code: *
* released to Public Domain. This code is ported from compress v4.0 *
* release joe. *
*--------------------------- Module Description --------------------------*
* The compress program is compatible with the compression/decompression *
* used on the Unix systems compress programs. This is version 4 and *
* supports up to 16 bits compression. The porting retained the Unix *
* meanings of all options, added a couple for MsDos and modified the *
* file name conventions to make more sense. *
* *
*--------------------------- Implementation Notes --------------------------*
* *
* compiled with : compress.h compress.fns *
* linked with : compapi.obj compusi.obj *
* problems: *
* See notes in compress.h for defines needed. *
* It should work now with Xenix *
* *
* Check the signal() handler functions in your compiler *
* documentation. This code assumes ANSI SYS V compatible *
* header and return values. Change as appropriate for your *
* compiler and operating system. *
* *
* This source compiles properly with Microsoft C compiler *
* version 5.1. *
* *
* CAUTION: because the program is in modules, make sure you recompile *
* all modules if you change the header or a define in the *
* compress.c file *
* *
* Algorithm from "A Technique for High Performance Data Compression", *
* Terry A. Welch, IEEE Computer Vol 17, No 6 (June 1984), pp 8-19. *
* *
* Assumptions: *
* When filenames are given, replaces with the compressed version *
* (.Z suffix) only if the file decreases in size. *
* Algorithm: *
* Modified Lempel-Ziv method (LZW). Basically finds common *
* substrings and replaces them with a variable size code. This is *
* deterministic, and can be done on the fly. Thus, the decompression *
* procedure needs no input table, but tracks the way the table was built. *
* *
* *
*--------------------------- Author(s) -------------------------*
* Initials ---- Name --------------------------------- *
* DjG Donald J. Gloistein *
* Plus many others, see rev.hst file for full list *
* LvR Lyle V. Rains, many thanks for improved implementation *
*************************************************************************@H*/
/*@R************************< Revision History >*****************************
* *
* version -- date -- init ---Notes---------------------- *
* 4.01 08-29-88 DjG first cut for 16 bit MsDos version *
* 09-04-88 DjG fixed unlink on zcat if interupted. *
* added msdos filename logic and functions *
* 4.10 10-27-88 DjG revised API with coding changes by LvR. *
* 4.10a 10-30-88 DjG cleaned up code and fixed bug in freeing ptr. *
* 4.10b 11-01-88 DjG cleaned up the logic for inpath/outpath *
* Changed the logic to finding the file name *
* Fixed the allocation bug in the api *
* Added some more portability macros *
* 4.10c 11-04-88 DjG Changed maxcode from global to static in api. *
* Supplied some library functions for those who *
* don't have them, changed dos usi to use the *
* strrpbrk(). Checked casts in api again. Compiles*
* without warnings at pick level 3. *
* 4.10d 11-25-88 DjG revised some memory allocation, put more in the *
* header file. Corrected some typos. *
* Changed prog_name() to force lower case *
* Corrected bug, no longer unlinks existing file *
* if not enough memory to compress or decompress *
* 12-06-88 DjG VERY minor changes for casts and header defines *
* 12-08-88 DjG Adjusted path separator check in main function *
* Amiga uses split seg because of compiler *
* 12-09-88 DjG Debugging done, all defaults now Unix compress *
* defaults, including unlinking input file and *
* acting as a filter. Must use -h option to get *
* help screen. *
* 4.10e 12-11-88 DjG Fixed more casts, prototypes and header file. *
* 4.10f 12-12-88 DjG Fixed unlinking open files on error. This fails *
* on shared or os/2 platforms. *
* 12-15-88 DjG Fixed SIGTYPE for function passed to signal *
* Fixed problems with Xenix 2.2.1 *
* 4.2 12-19-88 DjG Replaced adaptive reset as an option. *
* 4.3 12-26-88 DjG Fixed long file name bug, fixed bug with *
* compressdir. -B option added, same as -b option *
* 05-06-89 Dal Ported to Sozobon/Alcyon C for Atari ST. Also, *
* created get_one() for console prompting. *
* 05-08-89 Dal Ported to Minix-ST *
*************************************************************************@R*/
#include <stdio.h>
#define MAIN /* header has defining instances of globals */
#include "compress.h" /* contains the rest of the include file declarations */
#define ARGVAL() (*++(*argv) || (--argc && *++argv))
char suffix[] = SUFFIX ; /* only used in this file */
void main( argc, argv )
register int argc; char **argv;
{
char **filelist, **fileptr,*temp;
struct stat statbuf;
#ifndef NOSIGNAL
if ( (bgnd_flag = signal ( SIGINT, SIG_IGN )) != SIG_IGN ) {
/* ANSI/SYS V compatible */
/* the following test checks for error on setting signals */
/* check your documenta